package com.hoas.distributedlock.spring;

import com.hoas.distributedlock.core.DisributedLock;
import com.hoas.distributedlock.core.DisributedLockStrategy;
import org.springframework.data.redis.core.RedisTemplate;

public class SpringRedisLockStrategy extends DisributedLockStrategy {

    private RedisTemplate redisTemplate;

    private String prefix;

    public SpringRedisLockStrategy(String name, RedisTemplate redisTemplate, String prefix) {
        super(name);
        this.redisTemplate = redisTemplate;
        this.prefix = prefix;
    }

    protected DisributedLock create() {

        SpringRedisLock lock = new SpringRedisLock(redisTemplate);
        if (prefix != null && prefix.length() == 0) {
            lock.setPrefix( prefix );
        }
        return lock;

    }

}
